package com.dynamictpm.config;

import com.dynamictpm.toolkit.thread.QueueTypeEnum;
import com.dynamictpm.toolkit.thread.ThreadPoolBuilder;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 描述：： 公共线程池
 * <p>
 * ------------------------------------
 *
 * @program: dynamic-tpm
 * @ClassName CommonThreadPool
 * @author: it-yml
 * @create: 2023-07-05 10:11
 * @Version 1.0
 * --------------------------------------
 **/
public class CommonThreadPool {
    public static ThreadPoolExecutor getInstance(String threadPoolId) {
        ThreadPoolExecutor poolExecutor = ThreadPoolBuilder.builder()
                .isCustomPool(true)
                .threadFactory(threadPoolId)
                .poolThreadSize(3, 5)
                .keepAliveTime(1000L, TimeUnit.SECONDS)
//                .rejected(RejectedPolicies.runsOldestTaskPolicy())
                .workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE, 512)
                .build();
        return poolExecutor;
    }
}
